import { message } from 'antd'
import { post } from 'Api'
import * as Params from 'Api/post/params'

class PostStore {
  async writeArticle(params: Params.WriteArticleReq) {
    return await post.writeArticle(params)
  }

  async getArticle(params: Params.GetArticleReq) {
    const defaultRes = {
      list: [],
      totalCount: 0,
    }
    const res = await post.getArticle(params)
    if (res.success) {
      if (res.data.list) {
        return {
          list: res.data.list,
          totalCount: res.data.total_count,
        }
      }
      return defaultRes
    }
    message.error(`获取数据失败！${res.err_msg}`)
    return defaultRes
  }
  //上传头像
  async uploadAvatar(customFile:Blob) {
    return await post.uploadAvatar(
      customFile
    )
  }
  //删除评论
  async deleteComment(commentid:number){
    return await post.deleteComment(commentid)
  }

}

export default PostStore
